<template>
  <div>
    <HomeHeader></HomeHeader>
    <HomeSwiper :list="swiperList"></HomeSwiper>
    <HomeIcons :list="iconList"></HomeIcons>
    <HomeRecommend :list="recommendList"></HomeRecommend>
    <HomeWeekend :list="weekendList"></HomeWeekend>
  </div>
</template>

<script>
import HomeHeader from "./components/Header";
import HomeSwiper from "./components/Swiper";
import HomeIcons from "./components/Icons";
import HomeRecommend from "./components/Recommend";
import HomeWeekend from "./components/Weekend";
import { mapState } from "vuex";
import axios from "axios";

// import allData from "./data.js";

export default {
  name: "Home",
  components: {
    HomeHeader,
    HomeSwiper,
    HomeIcons,
    HomeRecommend,
    HomeWeekend,
  },
  data() {
    return {
      lastCity: "",
      swiperList: [],
      iconList: [],
      recommendList: [],
      weekendList: [],
    };
  },
  computed: {
    ...mapState(["city"]),
  },
  methods: {
    getHomeInfo() {
      // this.swiperList = allData.SwiperList;
      // this.iconList = allData.iconList;
      // for (let i = 0; i < 3; i++) {
      //   this.recommendList.push({
      //     id: "00" + i,
      //     imgUrl: "@/../static/images/jnh.jpg",
      //     title: "大连圣亚海洋世界",
      //     desc: "浪漫大连首站，浪漫的海洋主题乐园",
      //   });

      //   this.weekendList.push({
      //     id: "00" + i,
      //     imgUrl: "@/../static/images/ddyw.jpg",
      //     title: "大连圣亚海洋世界",
      //     desc: "浪漫大连首站，浪漫的海洋主题乐园",
      //   });
      // }

      // axios.get("/api/index.json?city=" + this.city).then(this.getHomeInfoSucc);
      axios.get("/api/index.json").then(this.getHomeInfoSucc);
    },
    getHomeInfoSucc(res) {
      res = res.data;
      if (res.ret && res.data) {
        const data = res.data;
        this.swiperList = data.swiperList;
        this.iconList = data.iconList;
        this.recommendList = data.recommendList;
        this.weekendList = data.weekendList;
      }
    },
  },
  mounted() {
    this.lastCity = this.city;
    this.getHomeInfo();
  },
  activated() {
    if (this.lastCity !== this.city) {
      this.lastCity = this.city;
      this.getHomeInfo();
    }
  },
};
</script>

<style>
</style>
